package com.demo.netty;

import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.codec.serialization.ClassResolvers;
import org.jboss.netty.handler.codec.serialization.ObjectDecoder;
import org.jboss.netty.handler.codec.serialization.ObjectEncoder;
import org.jboss.netty.util.Timer;

import static org.jboss.netty.channel.Channels.pipeline;

public class WorkerPipeline implements ChannelPipelineFactory {
    private Timer timer;
    private ClientBootstrap bootstrap;

    public static final int RECONNECT_DELAY = 5;

    public WorkerPipeline(ClientBootstrap bootstrap, Timer timer){
        super();
        this.timer = timer;
        this.bootstrap = bootstrap;
    }
    @Override
    public ChannelPipeline getPipeline() throws Exception {
        ChannelPipeline pipeline = pipeline();
        pipeline.addLast("decoder", new ObjectDecoder(ClassResolvers.weakCachingConcurrentResolver(null)));
        pipeline.addLast("encoder", new ObjectEncoder());
        pipeline.addLast("ClientHandler", new ClientHandler(bootstrap, timer));
        return pipeline;
    }
}
